import request, { type ListQuery, type ListResponse } from "@/utils/request";

const USER_PROFILE_BASE_URL = "/api";

const UserProfileAPI = {
  getUserProfileList: (params: UserProfileListParams) => {
    return request.get<any, ListResponse<UserProfileType>>(
      `${USER_PROFILE_BASE_URL}/internal/userProfile/`,
      {
        params,
      }
    );
  },
  addUserProfile: (data: any) => {
    return request.post(`${USER_PROFILE_BASE_URL}/internal/userProfile/`, data);
  },
  updateUserProfile: (data: Partial<UserProfileType>) => {
    return request.put(`${USER_PROFILE_BASE_URL}/internal/userProfile/${data.id}/`, data);
  },
  deleteUserProfile: (id: number) => {
    return request.delete(`${USER_PROFILE_BASE_URL}/internal/userProfile/${id}/`);
  },
  editUserPassowrd: (data: EditUserPassowrdForm) => {
    return request.post(`${USER_PROFILE_BASE_URL}/internal/pwd/modify/`, data);
  },
};

export type UserProfileListParams = {} & ListQuery;

export type UserProfileType = {
  id: number | string;
  username: string;
  nickname: string;
  avatar_url: File | string;
  balance: string;
  is_staff: boolean;
  is_superuser: boolean;
};

export type EditUserPassowrdForm = {
  user_id: string | number;
  new_pwd: string;
};

export default UserProfileAPI;
